import sqlalchemy as sa
from datetime import datetime, timezone
from database import db


class User(db.Model):
    __tablename__ = 'user'
    id = sa.Column(sa.Integer, primary_key=True)
    email = sa.Column(sa.String(255), unique=True, nullable=False)
    password = sa.Column(sa.String(255), nullable=False)
    name = sa.Column(sa.String(100), nullable=False)
    avatar = sa.Column(sa.String(500))
    amount = sa.Column(sa.Integer, default=0)
    created_at = sa.Column(sa.DateTime, default=datetime.now(timezone.utc))
    updated_at = sa.Column(sa.DateTime, default=datetime.now(timezone.utc), onupdate=datetime.now(timezone.utc))


class Theme(db.Model):
    __tablename__ = 'theme'
    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String(100), nullable=False)
    presets = db.relationship('Preset', backref='theme', lazy=True)


class Preset(db.Model):
    __tablename__ = 'preset'
    id = sa.Column(sa.Integer, primary_key=True)
    title = sa.Column(sa.String(200), nullable=False)
    content = sa.Column(sa.Text, nullable=False)
    theme_id = sa.Column(sa.Integer, sa.ForeignKey('theme.id'), nullable=False)


class Model(db.Model):
    __tablename__ = 'model'
    id = sa.Column(sa.Integer, primary_key=True)
    preview = sa.Column(sa.String(500))
    icon = sa.Column(sa.String(500))
    name = sa.Column(sa.String(100), nullable=False)
    description = sa.Column(sa.Text)
    group = sa.Column(sa.String(100))
    group_description = sa.Column(sa.Text)
    label = sa.Column(sa.String(200))
    is_hot = sa.Column(sa.Boolean, default=False)
    is_new = sa.Column(sa.Boolean, default=False)
    cost = sa.Column(sa.Integer, default=0)